#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

#include "body.h"

static void usage(void)
{
	std::cout	<< "Syntax Error!" << std::endl \
				<< "Usage: ./bin/nody <nBodys> <iterations> <timestep>" << std::endl;
	exit(1);
}

int main(int argc, char *argv[])
{
	unsigned int i,j;
	unsigned int nBodys = 5;
	unsigned int iterations = 100;
	double dt = 2000.0f;
	
	if (argc == 4)
	{
		nBodys		= atoi(argv[1]);
		iterations	= atoi(argv[2]);
		dt			= atof(argv[3]);
	}
	else usage();
	
	Body *bodys = new Body[nBodys]();
	
	std::cout << "# iterations: " << iterations << std::endl;
	std::cout << "# dt: " << dt << std::endl;
	std::cout << "# bodys: " << bodys->getBodyCount() << std::endl;
	
	/* init bodys */
	for (i=0; i<nBodys; i++)
	{
		bodys[i].setDt(dt);
		bodys[i].setMass(rand()%100 + 1);
		bodys[i].setPos(rand()%10-5, rand()%10-5);
	}
	
	/* perform simulation */
	for (i=0; i<iterations; i++)
	{
		for (j=0; j<nBodys; j++)
		{
			printf("%12.9lf %12.9lf ", bodys[j].posx, bodys[j].posy);
			bodys[j].calcNewPos(bodys);
		}
		printf("\n");
	}

	delete [] bodys;
	return EXIT_SUCCESS;
}

